<template>
    <div class="chat_container">
        <div class="tabs">
            <div v-for="(item, index) in navList" :key="index" @click="navClick(item)"
                :class="navIndex == item.label ? 'tabs_items_active' : 'tabs_items'">
                {{ item.label }}
            </div>
        </div>
        <div class="chat_contents" v-if="tabs" v-loading="oneloading">
            <div class="zanwu" v-if="onelist.length == 0">暂无数据</div>
            <div class="chat_contents_items" v-for="(item, index) in onelist" :key="index"
                @click="itemsClick(item, index)">
                <img class="chat_contents_items_img" :src="item.titleImage" alt="">
                <div class="chat_contents_right">
                    <div class="chat_contents_right_header">
                        <div class="chat_contents_right_header_title">{{ item.title }}</div>
                        <div class="chat_contents_right_header_time">{{ item.updateTime }}</div>
                    </div>
                    <div class="chat_contents_right_bottom">
                        {{ item.summary }}
                    </div>
                </div>
            </div>
            <div class="xiala" v-if="oneTotal > 5 && onequeryParams.pageNum * onequeryParams.pageSize < oneTotal">
                <img src="@/assets/下拉@2x.png" alt="" @click="pageClick()">
            </div>
        </div>
        <div class="chat_content" v-if="!tabs">
            <div class="titles">首页 > {{ activeDatas.type }}</div>
            <div class="header">{{ activeDatas.title }}</div>
            <div class="mes">
                <div class="people">发布人：{{ activeDatas.schoolName }}</div>
                <div>{{ activeDatas.updateTime }}</div>
            </div>
            <div class="line"></div>
            <div class="cons" v-html="activeDatas.content"></div>
            <div class="bottoms">
                <div class="prevTitle" @click="adds(activeDatas.prevId)" v-if="activeDatas.prevTitle">{{ '上一篇：' + activeDatas.prevTitle  }}</div>
                <div class="prevTitle" @click="adds(activeDatas.nextId)" v-if="activeDatas.nextTitle">{{ '下一篇：' + activeDatas.nextTitle  }}</div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { listNews,getNews } from '@/api/index'
const navList = ref([
    { label: '全部', value: '' },
    { label: '新闻', value: '1', }
])
const navIndex = ref('全部')
const onequeryParams = ref({
    pageNum: 1, pageSize: 5
})
const activeDatas = ref<any>({})
const tabs = ref(true)
const navClick = (item) => {
    tabs.value = true
    navIndex.value = item.label
    activeDatas.value = {}
    onequeryParams.value.pageNum = 1
    getOneList()
}
const oneloading = ref(false)
const onelist = ref([])
const oneTotal = ref(0)

// 右侧点击
const itemsClick = async(item, index) => {
    tabs.value = false
    const res = await getNews(item?.id)
    activeDatas.value = res.data
}

// 上一篇切换
const adds = async(id) => { 
    tabs.value = false
    const res = await getNews(id)
    activeDatas.value = res.data
}

// 一页五条 新闻
const getOneList = async () => {
    oneloading.value = true
    const res = await listNews(onequeryParams.value)
    res.rows.forEach(element => {
        element.updateTime = element.updateTime.split(' ')[0].replace(/-/g, ".")
        element.titleImage = import.meta.env.VITE_APP_PIC_URL + '/' + element.titleImage
    });
    oneTotal.value = res.total
    onelist.value = res.rows
    oneloading.value = false
}

// 首页分页
const pageClick = () => {
    onequeryParams.value.pageNum++
    getOneList()
}


onMounted(async () => {
    getOneList()
});

</script>

<style scoped lang="scss">
:deep(.el-textarea__inner) {
    min-height: 160px !important;
}

.chat_container {
    margin: 0;
    padding: 0;
    width: 100%;
    background-color: #f5f7fa;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    overflow: auto;
    box-sizing: content-box;
    padding-top: 100px;



    .tabs {
        width: 1400px;
        margin-bottom: 20px;
        margin-left: 20px;
        margin-top: 20px;
        display: flex;
        align-items: center;

        .tabs_items {
            margin-right: 30px;
            color: #A0A0A0;
            font-size: 16px;
            cursor: pointer;
        }

        .tabs_items_active {
            margin-right: 30px;
            color: #000000;
            font-size: 18px;
            cursor: pointer;
        }
    }

    .chat_contents {
        width: 1400px;
        background: #FFFFFF;
        box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, 0.09);
        border-radius: 20px;
        box-sizing: border-box;
        padding: 40px 50px;
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
        justify-content: flex-start;
        overflow: auto;

        .zanwu {
            width: 100%;
            line-height: 981px;
            text-align: center;
            color: #A0A0A0;
        }

        .xiala {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 20px;

            img {
                width: 28px;
                height: 28px;
                cursor: pointer;
            }
        }

        .chat_contents_items {
            width: 100%;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid rgb(237, 237, 237);

            .chat_contents_items_img {
                width: 200px;
                height: 150px;
                border-radius: 10px;
            }

            .chat_contents_right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
                width: calc(100% - 170px);

                .chat_contents_right_header {
                    display: flex;
                    align-items: center;
                    width: 100%;
                    justify-content: space-between;

                    .chat_contents_right_header_title {
                        font-size: 25px;
                        font-weight: 500;
                    }

                    .chat_contents_right_header_time {
                        color: #969696;
                        font-size: 14px;
                    }
                }

                .chat_contents_right_bottom {
                    color: #969696;
                    margin-top: 20px;
                    font-size: 14px;
                }
            }


        }
    }

    .chat_content {
        width: 1400px;
        background: #FFFFFF;
        box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, 0.09);
        border-radius: 20px;
        box-sizing: border-box;
        padding: 48px 60px;

        .titles {
            font-size: 16px;
        }

        .header {
            font-size: 25px;
            font-weight: 500;
            text-align: center;
            width: 100%;
            margin-top: 20px;
        }

        .mes {
            display: flex;
            align-items: center;
            justify-content: center;
            color: #969696;
            font-size: 14px;
            margin-top: 20px;

            .people {
                margin-right: 50px;
            }
        }

        .line {
            width: 100%;
            height: 1px;
            background-color: rgb(237, 237, 237);
            margin-top: 20px;
        }

        .cons {
            width: 100%;
        }

        .bottoms {
            margin-top: 40px;
            font-size: 14px;
            line-height: 1.5;
            .prevTitle{
                cursor: pointer;
            }
        }
    }
}
</style>